﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using MyCalendar.Utils;

namespace MyCalendar.UIcomponent
{
    public partial class DailyTaskListItem : UserControl
    {
        public DailyTaskListItem ()
        {
            InitializeComponent ();
            this.DataContext = this;
        }

        public DailyTaskListItem (DailyTask pTask, int pTotal, int pIndex)
        {
            InitializeComponent ();
            int _StartHour = pTask.StartTime.Hour;
            int _StopHour = pTask.EndTime.Hour;
            int _Duration = _StopHour - _StartHour;
            if (_Duration < 1)
            {
                _Duration = 1;
            }

            this.SetValue (Grid.RowProperty, _StartHour);
            this.SetValue (Grid.RowSpanProperty, _Duration);
            this.SetValue (Grid.ColumnProperty, 1);


            this.DataContext = this;

            MyWidth = 360 / pTotal;

            MyMargin = new Thickness ((360/pTotal)*(pIndex-1),0,0,0);

            MyHeight = 30 * _Duration;
        }

        public int MyHeight
        {
            get
            {
                return (int)GetValue (MyHeightProperty);
            }
            set
            {
                SetValue (MyHeightProperty, value);
            }
        }

        public static readonly DependencyProperty MyHeightProperty =
            DependencyProperty.Register ("MyHeight", typeof (int), typeof (DailyTaskListItem), null);

        public int MyWidth
        {
            get
            {
                return (int)GetValue (MyWidthProperty);
            }
            set
            {
                SetValue (MyWidthProperty, value);
            }
        }

        public static readonly DependencyProperty MyWidthProperty =
            DependencyProperty.Register ("MyWidth", typeof (int), typeof (DailyTaskListItem), null);

        public Thickness MyMargin
        {
            get
            {
                return (Thickness)GetValue (MyMarginProperty);
            }
            set
            {
                SetValue (MyMarginProperty, value);
            }
        }

        public static readonly DependencyProperty MyMarginProperty =
            DependencyProperty.Register ("MyPadding", typeof (Thickness), typeof (DailyTaskListItem), null);

    }
}
